package online.inote.common.constant;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;
import online.inote.common.exception.BusException;

/**
 * <p>
 * Desc: 文章类型枚举类
 * </p>
 *
 * @author XQF SUI
 * @created 2017年12月4日 上午11:01:36
 * @version 1.0
 */
@Getter
public enum ArticleType {
	
	ALL(0, "ALL"),
    JAVA(1, "Java"),
    SPARK(2, "Spark"),
    HADOOP(3, "Hadoop"),
    ELASTICSEARCH(4, "Android"),
    KAFKA(5, "CSS3"),
    SCALA(6, "HTML5");
    
	private static Map<Integer, ArticleType> articleTypeMap = new HashMap<>();
	private static Map<Integer, String> typeNameMap = new HashMap<>();
	
	static {
		for (ArticleType type : values()) {
			articleTypeMap.put(type.key, type);
			typeNameMap.put(type.key, type.name);
		}
	}
	
    private Integer key;
    private String name;
    
    private ArticleType(Integer key, String name) {
        this.key = key;
        this.name = name;
    }
    
    public static String getName(Integer key, boolean isEmpty) {
    	if (typeNameMap.containsKey(key)) {
    		return typeNameMap.get(key);
    	}
    	
    	if (isEmpty) return null;
    	throw new BusException("未知博客类型！");
    }
    
    public static ArticleType getArticleType(Integer key, boolean isEmpty) {
    	if (articleTypeMap.containsKey(key)) {
    		return articleTypeMap.get(key);
    	}
    	
    	if (isEmpty) return null;
    	throw new BusException("未知博客类型！");
    }
}
